package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.LunchBo;
import com.java2207.group1.pojo.Lunch;
import com.java2207.group1.service.LunchService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author AL 2022/7/26  21:00
 */
@Component
@Scope("prototype") //这里设置成多例模式
public class WebLunchListener extends AnalysisEventListener<LunchBo> {

    @Autowired
    private LunchService lunchService;
    @Override
    public void invoke(LunchBo data, AnalysisContext analysisContext) {
        Lunch lunch = new Lunch();
        BeanUtils.copyProperties(data,lunch);
        lunchService.addLunch(lunch);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
